package com.panopset;

import java.io.File;
import java.io.IOException;

import com.panopset.compat.RezIO;
import com.panopset.io.LockedWriter;

/**
 * Represents a manifest file addition.
 * 
 * @author Karl Dinwiddie
 * 
 */
public class ManifestFileAddition {

    private static final String PERMISSIONS_FILE_NAME = "permissions.txt";

    private String path;

    public String getPath() {
        if (path == null) {
            path = RezIO.getCanonicalPath(getFile());
        }
        return path;
    }

    private File file;

    private File getFile() {
        if (file == null) {
            file = new File(PERMISSIONS_FILE_NAME);
            if (!file.exists()) {
                try (LockedWriter fw = new LockedWriter(file)) {
                    fw.write(RezIO.loadTextFromResource(this.getClass(),
                            PERMISSIONS_FILE_NAME));
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return file;
    }

}
